home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / ODF Release 3 / ODFDev / ODF / OS / FWMenu / FWMnuBar.h < prev    next >
Encoding:
Text File  |  1996-12-16  |  8.4 KB  |  271 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWMnuBar.h
  4. //    Release Version:    $ ODF 3 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWMNUBAR_H
  11. #define FWMNUBAR_H
  12.  
  13. #ifndef FWPULLDM_H
  14. #include "FWPullDM.h"
  15. #endif
  16.  
  17. #ifndef FWCOMMON_H
  18. #include "FWCommon.h"
  19. #endif
  20.  
  21. #ifndef FWDEBUG_H
  22. #include "FWDebug.h"
  23. #endif
  24.  
  25. #ifndef FWTCOLL_H
  26. #include "FWTColl.h"
  27. #endif
  28.  
  29. // ----- OpenDoc Includes -----
  30.  
  31. #ifndef SOM_ODMenuBar_xh
  32. #include <MenuBar.xh>
  33. #endif
  34.  
  35. // ----- Platform Includes -----
  36.  
  37. #if defined(FW_BUILD_WIN) && !defined(_INC_WINDOWS)
  38. #include <windows.h>
  39. #endif
  40.  
  41. //========================================================================================
  42. //    Forward class definitions
  43. //========================================================================================
  44.  
  45. class ODPart;
  46. class FW_CString;
  47. class FW_CMenuItem;
  48.  
  49. //========================================================================================
  50. //    class FW_CMenuBar
  51. //========================================================================================
  52.  
  53. class FW_CMenuBar
  54. {
  55. //----------------------------------------------------------------------------------------
  56. //    Constructors/Destructors
  57. //
  58. public:
  59.     FW_DECLARE_AUTO(FW_CMenuBar)
  60.  
  61.     FW_CMenuBar(Environment* ev, ODPart* thePart, FW_Instance partInstance);
  62.     virtual ~FW_CMenuBar();
  63.     
  64. //----------------------------------------------------------------------------------------
  65. //    New API
  66. //
  67. public:
  68.     // ----- Adding -----
  69.     void                InitializeFromResource(Environment* ev, FW_ResourceID menuBarResourceID);
  70.     void                InitializeFromStream(Environment* ev, FW_CReadableStream& stream);
  71.     
  72.     void                 AdoptMenuFirst(Environment* ev, 
  73.                             FW_CPullDownMenu* menu);
  74.     void                 AdoptMenuLast(Environment* ev, 
  75.                             FW_CPullDownMenu* menu);
  76.                             
  77.     void                 AdoptMenuBefore(Environment* ev, 
  78.                             FW_CPullDownMenu* menu, 
  79.                             FW_CPullDownMenu* beforeMenu);    // if beforeMenu == NULL -> AdoptMenuFirst
  80.     void                 AdoptMenuAfter(Environment* ev, 
  81.                             FW_CPullDownMenu* menu, 
  82.                             FW_CPullDownMenu* afterMenu);    // if afterMenu == NULL -> AdoptMenuLast
  83.  
  84.     // ----- Removing/Detaching -----
  85.     void                 DetachMenu(Environment* ev, 
  86.                             FW_CPullDownMenu* menuToDetach);    
  87.     void                 DeleteMenu(Environment* ev, 
  88.                             FW_CPullDownMenu* menuToDelete);    // DetachMenu + delete of the menu
  89.     void                 DeleteAll(Environment* ev);
  90.  
  91.     void                RemoveItem(Environment* ev, ODCommandID commandID);
  92.     
  93.     // ----- Item access -----
  94.     void                 SetItemString(Environment* ev,
  95.                             ODCommandID commandID, 
  96.                             const FW_CString& itemString);
  97.     void                 GetItemString(Environment* ev, 
  98.                             ODCommandID commandID, 
  99.                             FW_CString& itemString) const;
  100.     
  101.     FW_CString            GetAboutString(Environment* ev) const;
  102.  
  103.     void                 EnableCommand(Environment* ev, 
  104.                             ODCommandID cmdNumber, 
  105.                             FW_Boolean enable);
  106.     void                 CheckCommand(Environment* ev, 
  107.                             ODCommandID cmdNumber, 
  108.                             FW_Boolean check);
  109.     void                 ToggleItem(Environment* ev, 
  110.                             ODCommandID cmdNumber, 
  111.                             FW_Boolean toggleState);
  112.                             
  113.     void                 EnableAndCheckCommand(Environment* ev, 
  114.                             ODCommandID cmdNumber, 
  115.                             FW_Boolean enable,
  116.                             FW_Boolean check);
  117.     void                 EnableAndToggleCommand(Environment* ev, 
  118.                             ODCommandID cmdNumber, 
  119.                             FW_Boolean enable,
  120.                             FW_Boolean toggleState);
  121.  
  122.     FW_MenuKey            GetMenuKey(Environment* ev, ODCommandID cmdNumber) const;
  123.     void                SetMenuKey(Environment* ev, ODCommandID cmdNumber, FW_MenuKey menuKey);
  124.                         
  125.     void                DisableAll(Environment* ev);
  126.     void                EnableAll(Environment* ev);
  127.     
  128.     // ----- Getters/Setters -----    
  129.     FW_CMenuItem*        GetMenuItemFromCommand(Environment* ev, 
  130.                             ODCommandID cmdNumber) const;
  131.                                 
  132.     ODMenuBar*            AcquireODMenuBar(Environment* ev) const;
  133.     ODPart*                GetODPart(Environment* ev) const;
  134.     
  135.     FW_CPullDownMenu*     FindMenuWithID(Environment* ev, ODMenuID menu) const;
  136.  
  137. //----------------------------------------------------------------------------------------
  138. //    Internal API
  139. //
  140. public:
  141.     void                 PrivDisplay(Environment* ev);    
  142.     
  143.     ODMenuID            PrivGetNewMenuID(Environment* ev);
  144.  
  145. #ifdef FW_BUILD_MAC
  146.     void                PrivMacEnableParentItem(Environment* ev, 
  147.                             ODCommandID cmdNumber);
  148.     
  149.     void                PrivMacRegisterCommand(Environment* ev,
  150.                             ODCommandID commandID,
  151.                             ODMenuID menuID,
  152.                             short itemID);
  153.     void                PrivMacUnregisterCommand(Environment* ev,
  154.                             ODCommandID commandID);
  155.     ODCommandID            PrivMacGetCommand(Environment* ev,
  156.                             ODMenuID menuID,
  157.                             short itemID);
  158.     
  159. #endif
  160.  
  161.     void                PrivAddSubMenu(Environment* ev,
  162.                             ODMenuID subMenuID,
  163.                             ODPlatformMenu platformMenu);
  164.     void                PrivRemoveMenu(Environment* ev, 
  165.                                         ODMenuID menuID);
  166.                             
  167. //----------------------------------------------------------------------------------------
  168. //    Platform specific API
  169. //
  170. #ifdef FW_BUILD_MAC
  171. public:
  172.     // ----- Enable/Disable of the whole menuBar -----
  173.     void                MacEnableMenuBar(Environment* ev, 
  174.                             FW_Boolean enable);
  175. #endif
  176.                         
  177. //----------------------------------------------------------------------------------------
  178. //    Data Members
  179. //
  180. private:
  181.     ODMenuBar*                                        fODMenuBar;
  182.     ODPart*                                            fODPart;
  183.     FW_TOrderedCollection<FW_CPullDownMenu>*        fPullDownMenuList;
  184.     ODMenuID                                        fNextMenuID;
  185.     FW_Instance                                        fPartInstance;
  186.     FW_CString                                        fAboutString;
  187. };
  188.  
  189. //========================================================================================
  190. //    FW_CMenuBar inlines
  191. //========================================================================================
  192.  
  193. //----------------------------------------------------------------------------------------
  194. //    FW_CMenuBar::PrivDisplay
  195. //----------------------------------------------------------------------------------------
  196. inline void FW_CMenuBar::PrivDisplay(Environment* ev)
  197. {
  198.     fODMenuBar->Display(ev);
  199. }
  200.  
  201. //----------------------------------------------------------------------------------------
  202. //    FW_CMenuBar::GetODPart
  203. //----------------------------------------------------------------------------------------
  204. inline ODPart* FW_CMenuBar::GetODPart(Environment*) const
  205. {
  206.     return fODPart;
  207. }
  208.  
  209. #ifdef FW_BUILD_MAC
  210. //----------------------------------------------------------------------------------------
  211. //    FW_CMenuBar::PrivMacRegisterCommand
  212. //----------------------------------------------------------------------------------------
  213. inline void FW_CMenuBar::PrivMacRegisterCommand(Environment* ev,
  214.                                                 ODCommandID commandID,
  215.                                                 ODMenuID menuID,
  216.                                                 short itemID)
  217. {
  218.     if (commandID > 0)    // filter out FW_kNoCommand and FW_kSeparatorCommand
  219.         fODMenuBar->RegisterCommand(ev, commandID, menuID, itemID);
  220. }
  221. #endif
  222.  
  223. #ifdef FW_BUILD_MAC
  224. //----------------------------------------------------------------------------------------
  225. //    FW_CMenuBar::PrivMacUnregisterCommand
  226. //----------------------------------------------------------------------------------------
  227. inline void FW_CMenuBar::PrivMacUnregisterCommand(Environment* ev, ODCommandID commandID)
  228. {
  229.     if (commandID > 0)    // filter out FW_kNoCommand and FW_kSeparatorCommand
  230.         fODMenuBar->UnregisterCommand(ev, commandID);
  231. }
  232. #endif
  233.     
  234. #ifdef FW_BUILD_MAC
  235. //----------------------------------------------------------------------------------------
  236. //    FW_CMenuBar::PrivMacGetCommand
  237. //----------------------------------------------------------------------------------------
  238. inline ODCommandID FW_CMenuBar::PrivMacGetCommand(Environment* ev,
  239.                                                 ODMenuID menuID,
  240.                                                 short itemID)
  241. {
  242.     return fODMenuBar->GetCommand(ev, menuID, itemID);
  243. }
  244. #endif
  245.     
  246. //----------------------------------------------------------------------------------------
  247. //    FW_CMenuBar::PrivAddSubMenu
  248. //----------------------------------------------------------------------------------------
  249. inline void FW_CMenuBar::PrivAddSubMenu(Environment* ev,
  250.                                         ODMenuID subMenuID,
  251.                                         ODPlatformMenu platformMenu)
  252. {
  253. #ifdef FW_BUILD_MAC
  254.     fODMenuBar->AddSubMenu(ev, subMenuID, platformMenu, fODPart);
  255. #endif
  256. #ifdef FW_BUILD_WIN
  257.     // [WIN_PORT] AddSubMenu is missing in OpenDoc/Win!
  258. #endif
  259. }
  260.  
  261. //----------------------------------------------------------------------------------------
  262. //    FW_CMenuBar::PrivRemoveMenu
  263. //----------------------------------------------------------------------------------------
  264. inline void FW_CMenuBar::PrivRemoveMenu(Environment* ev, 
  265.                                         ODMenuID menuID)
  266. {
  267.     fODMenuBar->RemoveMenu(ev, menuID);
  268. }
  269.  
  270. #endif
  271.